package com.yhhvip.lottery.controller;

import com.github.pagehelper.PageInfo;
import com.yhhvip.lottery.dao.mybatis.model.LotUser;
import com.yhhvip.lottery.domain.ReqAddSysUserVo;
import com.yhhvip.lottery.domain.ReqAffirmShipments;
import com.yhhvip.lottery.domain.ReqSearchUserVo;
import com.yhhvip.lottery.domain.ResLotSysUserRole;
import com.yhhvip.lottery.domain.res.ResLotUser;
import com.yhhvip.lottery.service.LotUserService;
import com.yhhvip.lottery.shiro.PasswordHelper;
import com.yhhvip.utils.BeanValidators;
import com.yhhvip.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("sys")
@Api(description = "系统用户相关API")
public class LotSysUserController {

    @Autowired
    private LotUserService lotUserService;

    @ApiOperation(value = "系统用户信息综合查询", produces = "application/json", notes = "系统用户信息综合查询")
    @ApiImplicitParam(name = "reqSearchUserVo", value = "请求参数实体", required = true, dataType = "ReqSearchUserVo")
    @PostMapping("users")
    public JsonResult searchUsers(@RequestBody ReqSearchUserVo reqSearchUserVo) {
        BeanValidators.validate(reqSearchUserVo);
        PageInfo<ResLotUser> pageInfo = lotUserService.selectSysUsersByPage(reqSearchUserVo);
        return JsonResult.ok(pageInfo);
    }


    @ApiOperation(value = "保存系统用户角色此处获取的参数的角色id是以 “,” 分隔的字符串", produces = "application/json", notes = "保存系统用户角色")
    @ApiImplicitParam(name = "resLotSysUserRole", value = "请求参数实体", required = true, dataType = "ResLotSysUserRole")
    @PostMapping("saveUserRoles")
    public JsonResult saveUserRoles(@RequestBody ResLotSysUserRole resLotSysUserRole) {
        BeanValidators.validate(resLotSysUserRole);
        int i = lotUserService.addSysUserRole(resLotSysUserRole);
        if (0 < i) {
            return JsonResult.ok();
        }
        return JsonResult.build("操作失败");
    }

    @ApiOperation(value = "删除系统用户信息", produces = "application/json", notes = "删除系统用户信息")
    @ApiImplicitParam(paramType = "path", name = "userId", value = "用户id", required = true, dataType = "Long", example = "1")
    @DeleteMapping(value = "delete/{userId}")
    public JsonResult delete(@PathVariable("userId") Long userId) {
        int i = lotUserService.delSysUser(userId);
        if (0 != i) {
            return JsonResult.ok();
        }
        return JsonResult.build("删除失败");
    }

    @ApiOperation(value = "确认发货", notes = "确认发货")
    @ApiImplicitParam(name = "reqAffirmShipments", value = "查询条件实体类", required = true, dataType = "ReqAffirmShipments")
    @PostMapping("affirm/shipments")
    public Object affirmShipments(@RequestBody ReqAffirmShipments reqAffirmShipments) {
        BeanValidators.validate(reqAffirmShipments);
        int i = lotUserService.affirmShipments(reqAffirmShipments);
        if (0 < i) {
            return JsonResult.ok();
        }
        return JsonResult.build("操作失败");
    }

}
